<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加密HTML</title>
    <style>
        .main {
            width: 60%;
            margin: 0 auto;
        }

        .main>* {
            margin-top: 10px;
        }

        textarea {
            border-radius: 3px;
            width: 100%;
            height: 200px;
        }

        #passData {
            width: 100%;
        }
    </style>
</head>

<body>
    <div class="main">
        <div>请输入密码</div>
        <input id="passData" placeholder="密码（越复杂安全性越好）" />
        <div>
            <label for="enableCompress">是否压缩</label>
            <input type="checkbox" id="enableCompress" checked="true">
        </div>
        <div>
            <label for="enableRemember">允许记住密码</label>
            <input type="checkbox" id="enableRemember" checked="true">
        </div>
        <div id="expireRemember">
            <span>记住密码有效期（单位：天）</span>
            <input id="expireDays" placeholder="默认：0（永不过期）" />
        </div>
        <div>请输入要加密的HTML内容</div>
        <textarea id="inputData" placeholder="<html><head>..."></textarea>
        <button id="genHTML">生成加密HTML</button>
        <textarea id="outputData" style="display: none;"></textarea>
        <button id="downHTML" style="display: none;">下载加密HTML文件</button>
    </div>
    <script>
        {const t=Uint8Array,e=Uint16Array,n=Int32Array,r=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),l=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),o=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),s=(t,r)=>{const l=new e(31);for(let e=0;e<31;++e)l[e]=r+=1<<t[e-1];const o=new n(l[30]);for(let t=1;t<30;++t)for(let e=l[t];e<l[t+1];++e)o[e]=e-l[t]<<5|t;return{b:l,r:o}},{b:f,r:c}=s(r,2);f[28]=258,c[258]=28;const{b:i,r:a}=s(l,0),h=new e(32768);for(let t=0;t<32768;++t){let e=(43690&t)>>1|(21845&t)<<1;e=(52428&e)>>2|(13107&e)<<2,e=(61680&e)>>4|(3855&e)<<4,h[t]=((65280&e)>>8|(255&e)<<8)>>1}const w=(t,n,r)=>{const l=t.length;let o=0;const s=new e(n);for(;o<l;++o)t[o]&&++s[t[o]-1];const f=new e(n);for(o=1;o<n;++o)f[o]=f[o-1]+s[o-1]<<1;let c;if(r){c=new e(1<<n);const r=15-n;for(o=0;o<l;++o)if(t[o]){const e=o<<4|t[o],l=n-t[o];let s=f[t[o]-1]++<<l;for(const t=s|(1<<l)-1;s<=t;++s)c[h[s]>>r]=e}}else for(c=new e(l),o=0;o<l;++o)t[o]&&(c[o]=h[f[t[o]-1]++]>>15-t[o]);return c},u=new t(288);for(let t=0;t<144;++t)u[t]=8;for(let t=144;t<256;++t)u[t]=9;for(let t=256;t<280;++t)u[t]=7;for(let t=280;t<288;++t)u[t]=8;const g=new t(32);for(let t=0;t<32;++t)g[t]=5;const m=w(u,9,0),M=w(g,5,0),b=t=>(t+7)/8|0,y=(e,n,r)=>((null==n||n<0)&&(n=0),(null==r||r>e.length)&&(r=e.length),new t(e.subarray(n,r))),p=(t,e,n)=>{n<<=7&e;const r=e/8|0;t[r]|=n,t[r+1]|=n>>8},x=(t,e,n)=>{n<<=7&e;const r=e/8|0;t[r]|=n,t[r+1]|=n>>8,t[r+2]|=n>>16},A=(n,r)=>{const l=[];for(let t=0;t<n.length;++t)n[t]&&l.push({s:t,f:n[t]});const o=l.length,s=l.slice();if(!o)return{t:j,l:0};if(1==o){const e=new t(l[0].s+1);return e[l[0].s]=1,{t:e,l:1}}l.sort(((t,e)=>t.f-e.f)),l.push({s:-1,f:25001});let f=l[0],c=l[1],i=0,a=1,h=2;for(l[0]={s:-1,f:f.f+c.f,l:f,r:c};a!=o-1;)f=l[l[i].f<l[h].f?i++:h++],c=l[i!=a&&l[i].f<l[h].f?i++:h++],l[a++]={s:-1,f:f.f+c.f,l:f,r:c};let w=s[0].s;for(let t=1;t<o;++t)s[t].s>w&&(w=s[t].s);const u=new e(w+1);let g=d(l[a-1],u,0);if(g>r){let t=0,e=0;const n=g-r,l=1<<n;for(s.sort(((t,e)=>u[e.s]-u[t.s]||t.f-e.f));t<o;++t){const n=s[t].s;if(!(u[n]>r))break;e+=l-(1<<g-u[n]),u[n]=r}for(e>>=n;e>0;){const n=s[t].s;u[n]<r?e-=1<<r-u[n]++-1:++t}for(;t>=0&&e;--t){const n=s[t].s;u[n]==r&&(--u[n],++e)}g=r}return{t:new t(u),l:g}},d=(t,e,n)=>-1==t.s?Math.max(d(t.l,e,n+1),d(t.r,e,n+1)):e[t.s]=n,k=t=>{let n=t.length;for(;n&&!t[--n];);const r=new e(++n);let l=0,o=t[0],s=1;const f=t=>{r[l++]=t};for(let e=1;e<=n;++e)if(t[e]==o&&e!=n)++s;else{if(!o&&s>2){for(;s>138;s-=138)f(32754);s>2&&(f(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(f(o),--s;s>6;s-=6)f(8304);s>2&&(f(s-3<<5|8208),s=0)}for(;s--;)f(o);s=1,o=t[e]}return{c:r.subarray(0,l),n:n}},v=(t,e)=>{let n=0;for(let r=0;r<e.length;++r)n+=t[r]*e[r];return n},U=(t,e,n)=>{const r=n.length,l=b(e+2);t[l]=255&r,t[l+1]=r>>8,t[l+2]=255^t[l],t[l+3]=255^t[l+1];for(let e=0;e<r;++e)t[l+e+4]=n[e];return 8*(l+4+r)},z=(t,n,s,f,c,i,a,h,b,y,d)=>{p(n,d++,s),++c[256];const{t:z,l:I}=A(c,15),{t:j,l:q}=A(i,15),{c:B,n:C}=k(z),{c:D,n:E}=k(j),F=new e(19);for(let t=0;t<B.length;++t)++F[31&B[t]];for(let t=0;t<D.length;++t)++F[31&D[t]];const{t:G,l:H}=A(F,7);let J=19;for(;J>4&&!G[o[J-1]];--J);const K=y+5<<3,L=v(c,u)+v(i,g)+a,N=v(c,z)+v(i,j)+a+14+3*J+v(F,G)+2*F[16]+3*F[17]+7*F[18];if(b>=0&&K<=L&&K<=N)return U(n,d,t.subarray(b,b+y));let O,P,Q,R;if(p(n,d,1+(N<L)),d+=2,N<L){O=w(z,I,0),P=z,Q=w(j,q,0),R=j;const t=w(G,H,0);p(n,d,C-257),p(n,d+5,E-1),p(n,d+10,J-4),d+=14;for(let t=0;t<J;++t)p(n,d+3*t,G[o[t]]);d+=3*J;const e=[B,D];for(let r=0;r<2;++r){const l=e[r];for(let e=0;e<l.length;++e){const r=31&l[e];p(n,d,t[r]),d+=G[r],r>15&&(p(n,d,l[e]>>5&127),d+=l[e]>>12)}}}else O=m,P=u,Q=M,R=g;for(let t=0;t<h;++t){const e=f[t];if(e>255){const t=e>>18&31;x(n,d,O[t+257]),d+=P[t+257],t>7&&(p(n,d,e>>23&31),d+=r[t]);const o=31&e;x(n,d,Q[o]),d+=R[o],o>3&&(x(n,d,e>>5&8191),d+=l[o])}else x(n,d,O[e]),d+=P[e]}return x(n,d,O[256]),d+P[256]},I=new n([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),j=new t(0),q=(o,s,f,i,h,w)=>{const u=w.z||o.length,g=new t(i+u+5*(1+Math.ceil(u/7e3))+h),m=g.subarray(i,g.length-h),M=w.l;let p=7&(w.r||0);if(s){p&&(m[0]=w.r>>3);const t=I[s-1],i=t>>13,h=8191&t,g=(1<<f)-1,b=w.p||new e(32768),y=w.h||new e(g+1),x=Math.ceil(f/3),A=2*x,d=t=>(o[t]^o[t+1]<<x^o[t+2]<<A)&g,k=new n(25e3),v=new e(288),U=new e(32);let j=0,q=0,B=w.i||0,C=0,D=w.w||0,E=0;for(;B+2<u;++B){const t=d(B);let e=32767&B,n=y[t];if(b[e]=n,y[t]=e,D<=B){const s=u-B;if((j>7e3||C>24576)&&(s>423||!M)){p=z(o,m,0,k,v,U,q,C,E,B-E,p),C=j=q=0,E=B;for(let t=0;t<286;++t)v[t]=0;for(let t=0;t<30;++t)U[t]=0}let f=2,w=0,g=h,y=e-n&32767;if(s>2&&t==d(B-y)){const t=Math.min(i,s)-1,r=Math.min(32767,B),l=Math.min(258,s);for(;y<=r&&--g&&e!=n;){if(o[B+f]==o[B+f-y]){let e=0;for(;e<l&&o[B+e]==o[B+e-y];++e);if(e>f){if(f=e,w=y,e>t)break;const r=Math.min(y,e-2);let l=0;for(let t=0;t<r;++t){const e=B-y+t&32767,r=e-b[e]&32767;r>l&&(l=r,n=e)}}}e=n,n=b[e],y+=e-n&32767}}if(w){k[C++]=268435456|c[f]<<18|a[w];const t=31&c[f],e=31&a[w];q+=r[t]+l[e],++v[257+t],++U[e],D=B+f,++j}else k[C++]=o[B],++v[o[B]]}}for(B=Math.max(B,D);B<u;++B)k[C++]=o[B],++v[o[B]];p=z(o,m,M,k,v,U,q,C,E,B-E,p),M||(w.r=7&p|m[p/8|0]<<3,p-=7,w.h=y,w.p=b,w.i=B,w.w=D)}else{for(let t=w.w||0;t<u+M;t+=65535){let e=t+65535;e>=u&&(m[p/8|0]=M,e=u),p=U(m,p+1,o.subarray(t,e))}w.i=u}return y(g,0,i+b(p)+h)},B=(e,n,r,l,o)=>{if(!o&&(o={l:1},n.dictionary)){const r=n.dictionary.subarray(-32768),l=new t(r.length+e.length);l.set(r),l.set(e,r.length),e=l,o.w=r.length}return q(e,null==n.level?6:n.level,null==n.mem?o.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(e.length)))):20:12+n.mem,r,l,o)};function deflateSync(t,e){return B(t,e||{},0,0)}}
    </script>
    <script>
        const sjcl = {
            cipher: {},
            hash: {},
            keyexchange: {},
            mode: {},
            misc: {},
            codec: {},
            exception: {
                corrupt: function (message) {
                    this.toString = function () { return "CORRUPT: " + this.message; };
                    this.message = message;
                },
                invalid: function (message) {
                    this.toString = function () { return "INVALID: " + this.message; };
                    this.message = message;
                },
                bug: function (message) {
                    this.toString = function () { return "BUG: " + this.message; };
                    this.message = message;
                },
                notReady: function (message) {
                    this.toString = function () { return "NOT READY: " + this.message; };
                    this.message = message;
                }
            }
        };
        sjcl.bitArray = {
            bitSlice: function (a, bstart, bend) {
                a = sjcl.bitArray._shiftRight(a.slice(bstart / 32), 32 - (bstart & 31)).slice(1);
                return (bend === undefined) ? a : sjcl.bitArray.clamp(a, bend - bstart);
            },
            concat: function (a1, a2) {
                if (a1.length === 0 || a2.length === 0) {
                    return a1.concat(a2);
                }
                let last = a1[a1.length - 1], shift = sjcl.bitArray.getPartial(last);
                if (shift === 32) {
                    return a1.concat(a2);
                } else {
                    return sjcl.bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
                }
            },
            bitLength: function (a) {
                let l = a.length, x;
                if (l === 0) { return 0; }
                x = a[l - 1];
                return (l - 1) * 32 + sjcl.bitArray.getPartial(x);
            },
            clamp: function (a, len) {
                if (a.length * 32 < len) { return a; }
                a = a.slice(0, Math.ceil(len / 32));
                let l = a.length;
                len = len & 31;
                if (l > 0 && len) {
                    a[l - 1] = sjcl.bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
                }
                return a;
            },
            partial: function (len, x, _end) {
                if (len === 32) { return x; }
                return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
            },
            getPartial: function (x) {
                return Math.round(x / 0x10000000000) || 32;
            },
            equal: function (a, b) {
                if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) {
                    return false;
                }
                let x = 0, i;
                for (i = 0; i < a.length; i++) {
                    x |= a[i] ^ b[i];
                }
                return (x === 0);
            },
            _shiftRight: function (a, shift, carry, out) {
                let i, last2 = 0, shift2;
                if (out === undefined) { out = []; }
                for (; shift >= 32; shift -= 32) {
                    out.push(carry);
                    carry = 0;
                }
                if (shift === 0) {
                    return out.concat(a);
                }
                for (i = 0; i < a.length; i++) {
                    out.push(carry | a[i] >>> shift);
                    carry = a[i] << (32 - shift);
                }
                last2 = a.length ? a[a.length - 1] : 0;
                shift2 = sjcl.bitArray.getPartial(last2);
                out.push(sjcl.bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
                return out;
            }
        };
        sjcl.codec.bytes = {
            fromBits: function (arr) {
                let out = [], bl = sjcl.bitArray.bitLength(arr), i, tmp;
                for (i = 0; i < bl / 8; i++) {
                    if ((i & 3) === 0) {
                        tmp = arr[i / 4];
                    }
                    out.push(tmp >>> 24);
                    tmp <<= 8;
                }
                return out;
            },
            toBits: function (bytes) {
                let out = [], i, tmp = 0;
                for (i = 0; i < bytes.length; i++) {
                    tmp = tmp << 8 | bytes[i];
                    if ((i & 3) === 3) {
                        out.push(tmp);
                        tmp = 0;
                    }
                }
                if (i & 3) {
                    out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
                }
                return out;
            }
        };
        sjcl.codec.utf8String = {
            fromBits: function (arr) {
                let out = "", bl = sjcl.bitArray.bitLength(arr), i, tmp;
                for (i = 0; i < bl / 8; i++) {
                    if ((i & 3) === 0) {
                        tmp = arr[i / 4];
                    }
                    out += String.fromCharCode(tmp >>> 8 >>> 8 >>> 8);
                    tmp <<= 8;
                }
                return decodeURIComponent(escape(out));
            },
            toBits: function (str) {
                str = unescape(encodeURIComponent(str));
                let out = [], i, tmp = 0;
                for (i = 0; i < str.length; i++) {
                    tmp = tmp << 8 | str.charCodeAt(i);
                    if ((i & 3) === 3) {
                        out.push(tmp);
                        tmp = 0;
                    }
                }
                if (i & 3) {
                    out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
                }
                return out;
            }
        };
        sjcl.hash.sha1 = function (hash) {
            if (hash) {
                this._h = hash._h.slice(0);
                this._buffer = hash._buffer.slice(0);
                this._length = hash._length;
            } else {
                this.reset();
            }
        };
        sjcl.hash.sha1.hash = function (data) {
            return (new sjcl.hash.sha1()).update(data).finalize();
        };
        sjcl.hash.sha1.prototype = {
            blockSize: 512,
            reset: function () {
                this._h = this._init.slice(0);
                this._buffer = [];
                this._length = 0;
                return this;
            },
            update: function (data) {
                if (typeof data === "string") {
                    data = sjcl.codec.utf8String.toBits(data);
                }
                let i, b = this._buffer = sjcl.bitArray.concat(this._buffer, data),
                    ol = this._length,
                    nl = this._length = ol + sjcl.bitArray.bitLength(data);
                if (nl > 9007199254740991) {
                    throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
                }
                if (typeof Uint32Array !== "undefined") {
                    let c = new Uint32Array(b);
                    let j = 0;
                    for (i = this.blockSize + ol - ((this.blockSize + ol) & (this.blockSize - 1)); i <= nl;
                        i += this.blockSize) {
                        this._block(c.subarray(16 * j, 16 * (j + 1)));
                        j += 1;
                    }
                    b.splice(0, 16 * j);
                } else {
                    for (i = this.blockSize + ol - ((this.blockSize + ol) & (this.blockSize - 1)); i <= nl;
                        i += this.blockSize) {
                        this._block(b.splice(0, 16));
                    }
                }
                return this;
            },
            finalize: function () {
                let i, b = this._buffer, h = this._h;
                b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]);
                for (i = b.length + 2; i & 15; i++) {
                    b.push(0);
                }
                b.push(Math.floor(this._length / 0x100000000));
                b.push(this._length | 0);
                while (b.length) {
                    this._block(b.splice(0, 16));
                }
                this.reset();
                return h;
            },
            _init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
            _key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
            _f: function (t, b, c, d) {
                if (t <= 19) {
                    return (b & c) | (~b & d);
                } else if (t <= 39) {
                    return b ^ c ^ d;
                } else if (t <= 59) {
                    return (b & c) | (b & d) | (c & d);
                } else if (t <= 79) {
                    return b ^ c ^ d;
                }
            },
            _S: function (n, x) {
                return (x << n) | (x >>> 32 - n);
            },
            _block: function (words) {
                let t, tmp, a, b, c, d, e,
                    h = this._h;
                let w;
                if (typeof Uint32Array !== "undefined") {
                    w = Array(80);
                    for (let j = 0; j < 16; j++) {
                        w[j] = words[j];
                    }
                } else {
                    w = words;
                }
                a = h[0]; b = h[1]; c = h[2]; d = h[3]; e = h[4];
                for (t = 0; t <= 79; t++) {
                    if (t >= 16) {
                        w[t] = this._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
                    }
                    tmp = (this._S(5, a) + this._f(t, b, c, d) + e + w[t] +
                        this._key[Math.floor(t / 20)]) | 0;
                    e = d;
                    d = c;
                    c = this._S(30, b);
                    b = a;
                    a = tmp;
                }
                h[0] = (h[0] + a) | 0;
                h[1] = (h[1] + b) | 0;
                h[2] = (h[2] + c) | 0;
                h[3] = (h[3] + d) | 0;
                h[4] = (h[4] + e) | 0;
            }
        };
        sjcl.cipher.aes = function (key) {
            if (!this._tables[0][0][0]) {
                this._precompute();
            }
            let i, j, tmp,
                encKey, decKey,
                sbox = this._tables[0][4], decTable = this._tables[1],
                keyLen = key.length, rcon = 1;
            if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
                throw new sjcl.exception.invalid("invalid aes key size");
            }
            this._key = [encKey = key.slice(0), decKey = []];
            for (i = keyLen; i < 4 * keyLen + 28; i++) {
                tmp = encKey[i - 1];
                if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
                    tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
                    if (i % keyLen === 0) {
                        tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
                        rcon = rcon << 1 ^ (rcon >> 7) * 283;
                    }
                }
                encKey[i] = encKey[i - keyLen] ^ tmp;
            }
            for (j = 0; i; j++, i--) {
                tmp = encKey[j & 3 ? i : i - 4];
                if (i <= 4 || j < 4) {
                    decKey[j] = tmp;
                } else {
                    decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
                        decTable[1][sbox[tmp >> 16 & 255]] ^
                        decTable[2][sbox[tmp >> 8 & 255]] ^
                        decTable[3][sbox[tmp & 255]];
                }
            }
        };
        sjcl.cipher.aes.prototype = {
            encrypt: function (data) { return this._crypt(data, 0); },
            decrypt: function (data) { return this._crypt(data, 1); },
            _tables: [[[], [], [], [], []], [[], [], [], [], []]],
            _precompute: function () {
                let encTable = this._tables[0], decTable = this._tables[1],
                    sbox = encTable[4], sboxInv = decTable[4],
                    i, x, xInv, d = [], th = [], x2, x4, x8, s, tEnc, tDec;
                for (i = 0; i < 256; i++) {
                    th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
                }
                for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
                    s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
                    s = s >> 8 ^ s & 255 ^ 99;
                    sbox[x] = s;
                    sboxInv[s] = x;
                    x8 = d[x4 = d[x2 = d[x]]];
                    tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
                    tEnc = d[s] * 0x101 ^ s * 0x1010100;
                    for (i = 0; i < 4; i++) {
                        encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
                        decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
                    }
                }
                for (i = 0; i < 5; i++) {
                    encTable[i] = encTable[i].slice(0);
                    decTable[i] = decTable[i].slice(0);
                }
            },
            _crypt: function (input, dir) {
                if (input.length !== 4) {
                    throw new sjcl.exception.invalid("invalid aes block size");
                }
                let key = this._key[dir],
                    a = input[0] ^ key[0],
                    b = input[dir ? 3 : 1] ^ key[1],
                    c = input[2] ^ key[2],
                    d = input[dir ? 1 : 3] ^ key[3],
                    a2, b2, c2,
                    nInnerRounds = key.length / 4 - 2,
                    i,
                    kIndex = 4,
                    out = [0, 0, 0, 0],
                    table = this._tables[dir],
                    t0 = table[0],
                    t1 = table[1],
                    t2 = table[2],
                    t3 = table[3],
                    sbox = table[4];
                for (i = 0; i < nInnerRounds; i++) {
                    a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
                    b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
                    c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
                    d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
                    kIndex += 4;
                    a = a2; b = b2; c = c2;
                }
                for (i = 0; i < 4; i++) {
                    out[dir ? 3 & -i : i] =
                        sbox[a >>> 24] << 24 ^
                        sbox[b >> 16 & 255] << 16 ^
                        sbox[c >> 8 & 255] << 8 ^
                        sbox[d & 255] ^
                        key[kIndex++];
                    a2 = a; a = b; b = c; c = d; d = a2;
                }
                return out;
            }
        };
        sjcl.misc.hmac = function (key, Hash) {
            this._hash = Hash = Hash || sjcl.hash.sha1;
            let exKey = [[], []], i,
                bs = Hash.prototype.blockSize / 32;
            this._baseHash = [new Hash(), new Hash()];
            if (key.length > bs) {
                key = Hash.hash(key);
            }
            for (i = 0; i < bs; i++) {
                exKey[0][i] = key[i] ^ 0x36363636;
                exKey[1][i] = key[i] ^ 0x5C5C5C5C;
            }
            this._baseHash[0].update(exKey[0]);
            this._baseHash[1].update(exKey[1]);
            this._resultHash = new Hash(this._baseHash[0]);
        };
        sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (data) {
            if (!this._updated) {
                this.update(data);
                return this.digest(data);
            } else {
                throw new sjcl.exception.invalid("encrypt on already updated hmac called!");
            }
        };
        sjcl.misc.hmac.prototype.reset = function () {
            this._resultHash = new this._hash(this._baseHash[0]);
            this._updated = false;
        };
        sjcl.misc.hmac.prototype.update = function (data) {
            this._updated = true;
            this._resultHash.update(data);
        };
        sjcl.misc.hmac.prototype.digest = function () {
            let w = this._resultHash.finalize(), result = new (this._hash)(this._baseHash[1]).update(w).finalize();
            this.reset();
            return result;
        };
        sjcl.misc.pbkdf2 = function (password, salt, count, length, Prff) {
            count = count || 10000;
            if (length < 0 || count < 0) {
                throw new sjcl.exception.invalid("invalid params to pbkdf2");
            }
            if (typeof password === "string") {
                password = sjcl.codec.utf8String.toBits(password);
            }
            if (typeof salt === "string") {
                salt = sjcl.codec.utf8String.toBits(salt);
            }
            Prff = Prff || sjcl.misc.hmac;
            let prf = new Prff(password),
                u, ui, i, j, k, out = [], b = sjcl.bitArray;
            for (k = 1; 32 * out.length < (length || 1); k++) {
                u = ui = prf.encrypt(b.concat(salt, [k]));
                for (i = 1; i < count; i++) {
                    ui = prf.encrypt(ui);
                    for (j = 0; j < ui.length; j++) {
                        u[j] ^= ui[j];
                    }
                }
                out = out.concat(u);
            }
            if (length) { out = b.clamp(out, length); }
            return out;
        };
        sjcl.random = {
            randomWords: function (nbytes) {
                function getCryptoModule() {
                    try {
                        return require("crypto");
                    }
                    catch (e) {
                        return null;
                    }
                }
                let crypto;
                if (typeof window !== "undefined") {
                    if (window.crypto) {
                        crypto = window.crypto;
                    } else if (window.msCrypto) {
                        crypto = window.msCrypto;
                    }
                } else if (typeof self !== "undefined" && self.crypto) {
                    crypto = self.crypto;
                } else if (typeof module !== "undefined" && module.exports) {
                    crypto = getCryptoModule();
                } else if (typeof global !== "undefined" && global.crypto) {
                    crypto = global.crypto;
                }
                try {
                    if (crypto) {
                        if (crypto.getRandomValues) {
                            return sjcl.codec.bytes.toBits(crypto.getRandomValues(new Uint8Array(nbytes)));
                        }
                        if (crypto.randomBytes) {
                            return sjcl.codec.bytes.toBits(new Uint8Array(crypto.randomBytes(nbytes)));
                        }
                    } else {
                        return getRandomValues(nbytes);
                    }
                } catch (e) {
                    return getRandomValues(nbytes);
                }
            },
            getRandomValues: function (nbytes) {
                let words = [];
                let r = function (m_w) {
                    let m_z = 0x3ade68b1;
                    let mask = 0xffffffff;
                    return function () {
                        m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
                        m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
                        let result = ((m_z << 0x10) + m_w) & mask;
                        result /= 0x100000000;
                        result += 0.5;
                        return result * (Math.random() > .5 ? 1 : -1);
                    };
                };
                for (let i = 0, rcache; i < nbytes; i += 4) {
                    let _r = r((rcache || Math.random()) * 0x100000000);
                    rcache = _r() * 0x3ade67b7;
                    words.push((_r() * 0x100000000) | 0);
                }
                return words;
            }
        };
        sjcl.mode.ctr = {
            name: "ctr",
            encrypt: function (prf, plaintext, iv) {
                return sjcl.mode.ctr._calculate(prf, plaintext, iv);
            },
            decrypt: function (prf, ciphertext, iv) {
                return sjcl.mode.ctr._calculate(prf, ciphertext, iv);
            },
            _calculate: function (prf, data, iv) {
                let l, bl, res, c, d, e, i;
                if (sjcl.bitArray.bitLength(iv) !== 128) {
                    throw new sjcl.exception.invalid("ctr iv must be 128 bits");
                }
                if (!(l = data.length)) {
                    return [];
                }
                c = iv.slice(0);
                d = data.slice(0);
                bl = sjcl.bitArray.bitLength(d);
                for (i = 0; i < l; i += 4) {
                    e = prf.encrypt(c);
                    d[i] ^= e[0];
                    d[i + 1] ^= e[1];
                    d[i + 2] ^= e[2];
                    d[i + 3] ^= e[3];
                    for (let carry = 3; carry >= 0; carry--) {
                        if (++c[carry]) break;
                    }
                }
                return sjcl.bitArray.clamp(d, bl);
            }
        };
    </script>
    <script>
        enableRemember.onchange = () => {
            expireRemember.style.display = enableRemember.checked ? "block" : "none";
        }
        genHTML.onclick = () => {
            downHTML.style.display = outputData.style.display = "none";
            if (!passData.value) {
                alert("密码不能为空！");
                return;
            }
            if (!inputData.value) {
                alert("HTML不能为空！");
                return;
            }
            encryptString(inputData.value, passData.value);
        }
        downHTML.onclick = () => {
            let a = document.createElement("a");
            a.download = "encrypted_index.html";
            a.href = URL.createObjectURL(new Blob([outputData.value]));
            a.click();
        }
        const encoder = new TextEncoder();
        const decoder = new TextDecoder();
        const passwordVerifierLen = 4;
        const aesKeyLen = 16;
        const saltLen = 8;
        function encryptString(data, password) {
            const salt = sjcl.random.randomWords(saltLen);
            const derivedKey = sjcl.misc.pbkdf2(password, salt, 1000, (aesKeyLen + passwordVerifierLen) * 8);
            const aesKey = sjcl.bitArray.bitSlice(derivedKey, 0, aesKeyLen * 8);
            const derivedPassVerifier = sjcl.bitArray.bitSlice(derivedKey, aesKeyLen * 8);
            const preData = sjcl.bitArray.concat(salt, derivedPassVerifier);
            let uint8Data = encoder.encode(data);
            if (enableCompress.checked) {
                uint8Data = deflateSync(uint8Data);
            }
            const result = sjcl.mode.ctr.encrypt(new sjcl.cipher.aes(aesKey), sjcl.codec.bytes.toBits(uint8Data), [0, 0, 0, 0]);
            const reader = new FileReader()
            reader.onload = () => {
                let baseRes = reader.result.substring(reader.result.indexOf(',') + 1);
                let htmlRes = `<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加密页面</title>
    <style>
        * {
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji" !important;
        }

        #loadMask {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 100;
            background-color: #edeff2;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        #loadMask>div {
            text-align: center;
        }

        #loadMask>div>div {
            font-size: 40px;
            color: #909090;
        }

        #loadMask svg {
            width: 160px;
            height: 80px;
        }

        .passArea {
            width: 200px;
        }

        #passData {
            height: 40px;
            display: block;
            outline: none;
            border: none;
            width: 100%;
            padding-left: 10px;
            font-size: 18px;
            border-radius: 3px;
            -webkit-text-security: disc;
        }

        .activeBtn {
            background: #99c959 !important;
        }

        label {
            margin-top: 8px;
            font-size: 16px;
            display: flex;
            color: #909090;
            align-items: center;
            line-height: 20px;
            height: 20px;
        }

        #rememberMe {
            -webkit-appearance: none;
            appearance: none;
            width: 20px;
            height: 20px;
            border: 2px solid #909090;
            border-radius: 2px;
            margin: 0 8px 0 0;
        }

        #rememberMe::before {
            content: "";
            display: block;
            /* margin: 1px; */
            width: 16px;
            height: 16px;
            transform: scale(0);
            background: #99c959;
            clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
        }

        #rememberMe:checked::before {
            transform: scale(1);
        }

        #goChat {
            margin-top: 8px;
            font-size: 18px;
            background: #b8da8b;
            border-radius: 3px;
            height: 100%;
            color: white;
            padding: 0 15px;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id="loadMask">
        <div>
            <div>ChatGPT</div>
            <svg viewBox="0 0 200 100" preserveAspectRatio="xMidYMid">
                <g transform="translate(50 50)">
                    <circle cx="0" cy="0" r="15" fill="#e15b64">
                        <animateTransform attributeName="transform" type="scale" begin="-0.3333333333333333s"
                            calcMode="spline" keySplines="0.3 0 0.7 1;0.3 0 0.7 1" values="0;1;0" keyTimes="0;0.5;1"
                            dur="1s" repeatCount="indefinite"></animateTransform>
                    </circle>
                </g>
                <g transform="translate(100 50)">
                    <circle cx="0" cy="0" r="15" fill="#f8b26a">
                        <animateTransform attributeName="transform" type="scale" begin="-0.16666666666666666s"
                            calcMode="spline" keySplines="0.3 0 0.7 1;0.3 0 0.7 1" values="0;1;0" keyTimes="0;0.5;1"
                            dur="1s" repeatCount="indefinite"></animateTransform>
                    </circle>
                </g>
                <g transform="translate(150 50)">
                    <circle cx="0" cy="0" r="15" fill="#99c959">
                        <animateTransform attributeName="transform" type="scale" begin="0s" calcMode="spline"
                            keySplines="0.3 0 0.7 1;0.3 0 0.7 1" values="0;1;0" keyTimes="0;0.5;1" dur="1s"
                            repeatCount="indefinite"></animateTransform>
                    </circle>
                </g>
            </svg>
            <div class="passArea">
                <input id="passData" type="text" placeholder="请输入密码" autocomplete="off" />
                `+ (enableRemember.checked ? `<label for="rememberMe">
                    <input type="checkbox" id="rememberMe" checked="true">
                    记住密码
                </label>`: "") +
                    `<div id="goChat">开始</div>
            </div>
        </div>
    </div>
    ` + (enableCompress.checked ? `<script>
        {const t=Uint8Array,n=Uint16Array,e=Int32Array,r=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),o=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),l=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),s=(t,r)=>{const o=new n(31);for(let n=0;n<31;++n)o[n]=r+=1<<t[n-1];const l=new e(o[30]);for(let t=1;t<30;++t)for(let n=o[t];n<o[t+1];++n)l[n]=n-o[t]<<5|t;return{b:o,r:l}},{b:c,r:i}=s(r,2);c[28]=258,i[258]=28;const{b:a,r:f}=s(o,0),u=new n(32768);for(let t=0;t<32768;++t){let n=(43690&t)>>1|(21845&t)<<1;n=(52428&n)>>2|(13107&n)<<2,n=(61680&n)>>4|(3855&n)<<4,u[t]=((65280&n)>>8|(255&n)<<8)>>1}const w=(t,e,r)=>{const o=t.length;let l=0;const s=new n(e);for(;l<o;++l)t[l]&&++s[t[l]-1];const c=new n(e);for(l=1;l<e;++l)c[l]=c[l-1]+s[l-1]<<1;let i;if(r){i=new n(1<<e);const r=15-e;for(l=0;l<o;++l)if(t[l]){const n=l<<4|t[l],o=e-t[l];let s=c[t[l]-1]++<<o;for(const t=s|(1<<o)-1;s<=t;++s)i[u[s]>>r]=n}}else for(i=new n(o),l=0;l<o;++l)t[l]&&(i[l]=u[c[t[l]-1]++]>>15-t[l]);return i},b=new t(288);for(let t=0;t<144;++t)b[t]=8;for(let t=144;t<256;++t)b[t]=9;for(let t=256;t<280;++t)b[t]=7;for(let t=280;t<288;++t)b[t]=8;const d=new t(32);for(let t=0;t<32;++t)d[t]=5;const h=w(b,9,1),g=w(d,5,1),y=t=>{let n=t[0];for(let e=1;e<t.length;++e)t[e]>n&&(n=t[e]);return n},k=(t,n,e)=>{const r=n/8|0;return(t[r]|t[r+1]<<8)>>(7&n)&e},m=(t,n)=>{const e=n/8|0;return(t[e]|t[e+1]<<8|t[e+2]<<16)>>(7&n)},p=t=>(t+7)/8|0,v=(n,e,r)=>((null==e||e<0)&&(e=0),(null==r||r>n.length)&&(r=n.length),new t(n.subarray(e,r))),E=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],x=(t,n,e)=>{const r=new Error(n||E[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,x),!e)throw r;return r},A=(n,e,s,i)=>{const f=n.length,u=i?i.length:0;if(!f||e.f&&!e.l)return s||new t(0);const b=!s,d=b||2!=e.i,E=e.i;b&&(s=new t(3*f));const A=n=>{let e=s.length;if(n>e){const r=new t(Math.max(2*e,n));r.set(s),s=r}};let T=e.f||0,U=e.p||0,F=e.b||0,M=e.l,S=e.d,z=e.m,I=e.n;const O=8*f;do{if(!M){T=k(n,U,1);const r=k(n,U+1,3);if(U+=3,!r){const t=p(U)+4,r=n[t-4]|n[t-3]<<8,o=t+r;if(o>f){E&&x(0);break}d&&A(F+r),s.set(n.subarray(t,o),F),e.b=F+=r,e.p=U=8*o,e.f=T;continue}if(1==r)M=h,S=g,z=9,I=5;else if(2==r){const e=k(n,U,31)+257,r=k(n,U+10,15)+4,o=e+k(n,U+5,31)+1;U+=14;const s=new t(o),c=new t(19);for(let t=0;t<r;++t)c[l[t]]=k(n,U+3*t,7);U+=3*r;const i=y(c),a=(1<<i)-1,f=w(c,i,1);for(let t=0;t<o;){const e=f[k(n,U,a)];U+=15&e;const r=e>>4;if(r<16)s[t++]=r;else{let e=0,o=0;for(16==r?(o=3+k(n,U,3),U+=2,e=s[t-1]):17==r?(o=3+k(n,U,7),U+=3):18==r&&(o=11+k(n,U,127),U+=7);o--;)s[t++]=e}}const u=s.subarray(0,e),b=s.subarray(e);z=y(u),I=y(b),M=w(u,z,1),S=w(b,I,1)}else x(1);if(U>O){E&&x(0);break}}d&&A(F+131072);const b=(1<<z)-1,v=(1<<I)-1;let j=U;for(;;j=U){const t=M[m(n,U)&b],e=t>>4;if(U+=15&t,U>O){E&&x(0);break}if(t||x(2),e<256)s[F++]=e;else{if(256==e){j=U,M=null;break}{let t=e-254;if(e>264){const o=e-257,l=r[o];t=k(n,U,(1<<l)-1)+c[o],U+=l}const l=S[m(n,U)&v],f=l>>4;l||x(3),U+=15&l;let w=a[f];if(f>3){const t=o[f];w+=m(n,U)&(1<<t)-1,U+=t}if(U>O){E&&x(0);break}d&&A(F+131072);const b=F+t;if(F<w){const t=u-w,n=Math.min(w,b);for(t+F<0&&x(3);F<n;++F)s[F]=i[t+F]}for(;F<b;++F)s[F]=s[F-w]}}}e.l=M,e.p=j,e.b=F,e.f=T,M&&(T=1,e.m=z,e.d=S,e.n=I)}while(!T);return F!=s.length&&b?v(s,0,F):s.subarray(0,F)};function inflateSync(t,n){return A(t,{i:2},n&&n.out,n&&n.dictionary)}}
    <\/script>` : "") +
                    `<script>
        const sjcl = {
            cipher: {},
            hash: {},
            keyexchange: {},
            mode: {},
            misc: {},
            codec: {},
            exception: {
                corrupt: function (message) {
                    this.toString = function () {return "CORRUPT: " + this.message;};
                    this.message = message;
                },
                invalid: function (message) {
                    this.toString = function () {return "INVALID: " + this.message;};
                    this.message = message;
                },
                bug: function (message) {
                    this.toString = function () {return "BUG: " + this.message;};
                    this.message = message;
                },
                notReady: function (message) {
                    this.toString = function () {return "NOT READY: " + this.message;};
                    this.message = message;
                }
            }
        };
        sjcl.bitArray = {
            bitSlice: function (a, bstart, bend) {
                a = sjcl.bitArray._shiftRight(a.slice(bstart / 32), 32 - (bstart & 31)).slice(1);
                return (bend === undefined) ? a : sjcl.bitArray.clamp(a, bend - bstart);
            },
            concat: function (a1, a2) {
                if (a1.length === 0 || a2.length === 0) {
                    return a1.concat(a2);
                }
                let last = a1[a1.length - 1], shift = sjcl.bitArray.getPartial(last);
                if (shift === 32) {
                    return a1.concat(a2);
                } else {
                    return sjcl.bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
                }
            },
            bitLength: function (a) {
                let l = a.length, x;
                if (l === 0) {return 0;}
                x = a[l - 1];
                return (l - 1) * 32 + sjcl.bitArray.getPartial(x);
            },
            clamp: function (a, len) {
                if (a.length * 32 < len) {return a;}
                a = a.slice(0, Math.ceil(len / 32));
                let l = a.length;
                len = len & 31;
                if (l > 0 && len) {
                    a[l - 1] = sjcl.bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
                }
                return a;
            },
            partial: function (len, x, _end) {
                if (len === 32) {return x;}
                return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
            },
            getPartial: function (x) {
                return Math.round(x / 0x10000000000) || 32;
            },
            equal: function (a, b) {
                if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) {
                    return false;
                }
                let x = 0, i;
                for (i = 0; i < a.length; i++) {
                    x |= a[i] ^ b[i];
                }
                return (x === 0);
            },
            _shiftRight: function (a, shift, carry, out) {
                let i, last2 = 0, shift2;
                if (out === undefined) {out = [];}
                for (; shift >= 32; shift -= 32) {
                    out.push(carry);
                    carry = 0;
                }
                if (shift === 0) {
                    return out.concat(a);
                }
                for (i = 0; i < a.length; i++) {
                    out.push(carry | a[i] >>> shift);
                    carry = a[i] << (32 - shift);
                }
                last2 = a.length ? a[a.length - 1] : 0;
                shift2 = sjcl.bitArray.getPartial(last2);
                out.push(sjcl.bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
                return out;
            }
        };
        sjcl.codec.bytes = {
            fromBits: function (arr) {
                let out = [], bl = sjcl.bitArray.bitLength(arr), i, tmp;
                for (i = 0; i < bl / 8; i++) {
                    if ((i & 3) === 0) {
                        tmp = arr[i / 4];
                    }
                    out.push(tmp >>> 24);
                    tmp <<= 8;
                }
                return out;
            },
            toBits: function (bytes) {
                let out = [], i, tmp = 0;
                for (i = 0; i < bytes.length; i++) {
                    tmp = tmp << 8 | bytes[i];
                    if ((i & 3) === 3) {
                        out.push(tmp);
                        tmp = 0;
                    }
                }
                if (i & 3) {
                    out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
                }
                return out;
            }
        };
        sjcl.codec.utf8String = {
            fromBits: function (arr) {
                let out = "", bl = sjcl.bitArray.bitLength(arr), i, tmp;
                for (i = 0; i < bl / 8; i++) {
                    if ((i & 3) === 0) {
                        tmp = arr[i / 4];
                    }
                    out += String.fromCharCode(tmp >>> 8 >>> 8 >>> 8);
                    tmp <<= 8;
                }
                return decodeURIComponent(escape(out));
            },
            toBits: function (str) {
                str = unescape(encodeURIComponent(str));
                let out = [], i, tmp = 0;
                for (i = 0; i < str.length; i++) {
                    tmp = tmp << 8 | str.charCodeAt(i);
                    if ((i & 3) === 3) {
                        out.push(tmp);
                        tmp = 0;
                    }
                }
                if (i & 3) {
                    out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
                }
                return out;
            }
        };
        sjcl.hash.sha1 = function (hash) {
            if (hash) {
                this._h = hash._h.slice(0);
                this._buffer = hash._buffer.slice(0);
                this._length = hash._length;
            } else {
                this.reset();
            }
        };
        sjcl.hash.sha1.hash = function (data) {
            return (new sjcl.hash.sha1()).update(data).finalize();
        };
        sjcl.hash.sha1.prototype = {
            blockSize: 512,
            reset: function () {
                this._h = this._init.slice(0);
                this._buffer = [];
                this._length = 0;
                return this;
            },
            update: function (data) {
                if (typeof data === "string") {
                    data = sjcl.codec.utf8String.toBits(data);
                }
                let i, b = this._buffer = sjcl.bitArray.concat(this._buffer, data),
                    ol = this._length,
                    nl = this._length = ol + sjcl.bitArray.bitLength(data);
                if (nl > 9007199254740991) {
                    throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
                }
                if (typeof Uint32Array !== "undefined") {
                    let c = new Uint32Array(b);
                    let j = 0;
                    for (i = this.blockSize + ol - ((this.blockSize + ol) & (this.blockSize - 1)); i <= nl;
                        i += this.blockSize) {
                        this._block(c.subarray(16 * j, 16 * (j + 1)));
                        j += 1;
                    }
                    b.splice(0, 16 * j);
                } else {
                    for (i = this.blockSize + ol - ((this.blockSize + ol) & (this.blockSize - 1)); i <= nl;
                        i += this.blockSize) {
                        this._block(b.splice(0, 16));
                    }
                }
                return this;
            },
            finalize: function () {
                let i, b = this._buffer, h = this._h;
                b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]);
                for (i = b.length + 2; i & 15; i++) {
                    b.push(0);
                }
                b.push(Math.floor(this._length / 0x100000000));
                b.push(this._length | 0);
                while (b.length) {
                    this._block(b.splice(0, 16));
                }
                this.reset();
                return h;
            },
            _init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
            _key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
            _f: function (t, b, c, d) {
                if (t <= 19) {
                    return (b & c) | (~b & d);
                } else if (t <= 39) {
                    return b ^ c ^ d;
                } else if (t <= 59) {
                    return (b & c) | (b & d) | (c & d);
                } else if (t <= 79) {
                    return b ^ c ^ d;
                }
            },
            _S: function (n, x) {
                return (x << n) | (x >>> 32 - n);
            },
            _block: function (words) {
                let t, tmp, a, b, c, d, e,
                    h = this._h;
                let w;
                if (typeof Uint32Array !== "undefined") {
                    w = Array(80);
                    for (let j = 0; j < 16; j++) {
                        w[j] = words[j];
                    }
                } else {
                    w = words;
                }
                a = h[0]; b = h[1]; c = h[2]; d = h[3]; e = h[4];
                for (t = 0; t <= 79; t++) {
                    if (t >= 16) {
                        w[t] = this._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
                    }
                    tmp = (this._S(5, a) + this._f(t, b, c, d) + e + w[t] +
                        this._key[Math.floor(t / 20)]) | 0;
                    e = d;
                    d = c;
                    c = this._S(30, b);
                    b = a;
                    a = tmp;
                }
                h[0] = (h[0] + a) | 0;
                h[1] = (h[1] + b) | 0;
                h[2] = (h[2] + c) | 0;
                h[3] = (h[3] + d) | 0;
                h[4] = (h[4] + e) | 0;
            }
        };
        sjcl.cipher.aes = function (key) {
            if (!this._tables[0][0][0]) {
                this._precompute();
            }
            let i, j, tmp,
                encKey, decKey,
                sbox = this._tables[0][4], decTable = this._tables[1],
                keyLen = key.length, rcon = 1;
            if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
                throw new sjcl.exception.invalid("invalid aes key size");
            }
            this._key = [encKey = key.slice(0), decKey = []];
            for (i = keyLen; i < 4 * keyLen + 28; i++) {
                tmp = encKey[i - 1];
                if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
                    tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
                    if (i % keyLen === 0) {
                        tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
                        rcon = rcon << 1 ^ (rcon >> 7) * 283;
                    }
                }
                encKey[i] = encKey[i - keyLen] ^ tmp;
            }
            for (j = 0; i; j++, i--) {
                tmp = encKey[j & 3 ? i : i - 4];
                if (i <= 4 || j < 4) {
                    decKey[j] = tmp;
                } else {
                    decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
                        decTable[1][sbox[tmp >> 16 & 255]] ^
                        decTable[2][sbox[tmp >> 8 & 255]] ^
                        decTable[3][sbox[tmp & 255]];
                }
            }
        };
        sjcl.cipher.aes.prototype = {
            encrypt: function (data) {return this._crypt(data, 0);},
            decrypt: function (data) {return this._crypt(data, 1);},
            _tables: [[[], [], [], [], []], [[], [], [], [], []]],
            _precompute: function () {
                let encTable = this._tables[0], decTable = this._tables[1],
                    sbox = encTable[4], sboxInv = decTable[4],
                    i, x, xInv, d = [], th = [], x2, x4, x8, s, tEnc, tDec;
                for (i = 0; i < 256; i++) {
                    th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
                }
                for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
                    s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
                    s = s >> 8 ^ s & 255 ^ 99;
                    sbox[x] = s;
                    sboxInv[s] = x;
                    x8 = d[x4 = d[x2 = d[x]]];
                    tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
                    tEnc = d[s] * 0x101 ^ s * 0x1010100;
                    for (i = 0; i < 4; i++) {
                        encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
                        decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
                    }
                }
                for (i = 0; i < 5; i++) {
                    encTable[i] = encTable[i].slice(0);
                    decTable[i] = decTable[i].slice(0);
                }
            },
            _crypt: function (input, dir) {
                if (input.length !== 4) {
                    throw new sjcl.exception.invalid("invalid aes block size");
                }
                let key = this._key[dir],
                    a = input[0] ^ key[0],
                    b = input[dir ? 3 : 1] ^ key[1],
                    c = input[2] ^ key[2],
                    d = input[dir ? 1 : 3] ^ key[3],
                    a2, b2, c2,
                    nInnerRounds = key.length / 4 - 2,
                    i,
                    kIndex = 4,
                    out = [0, 0, 0, 0],
                    table = this._tables[dir],
                    t0 = table[0],
                    t1 = table[1],
                    t2 = table[2],
                    t3 = table[3],
                    sbox = table[4];
                for (i = 0; i < nInnerRounds; i++) {
                    a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
                    b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
                    c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
                    d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
                    kIndex += 4;
                    a = a2; b = b2; c = c2;
                }
                for (i = 0; i < 4; i++) {
                    out[dir ? 3 & -i : i] =
                        sbox[a >>> 24] << 24 ^
                        sbox[b >> 16 & 255] << 16 ^
                        sbox[c >> 8 & 255] << 8 ^
                        sbox[d & 255] ^
                        key[kIndex++];
                    a2 = a; a = b; b = c; c = d; d = a2;
                }
                return out;
            }
        };
        sjcl.misc.hmac = function (key, Hash) {
            this._hash = Hash = Hash || sjcl.hash.sha1;
            let exKey = [[], []], i,
                bs = Hash.prototype.blockSize / 32;
            this._baseHash = [new Hash(), new Hash()];
            if (key.length > bs) {
                key = Hash.hash(key);
            }
            for (i = 0; i < bs; i++) {
                exKey[0][i] = key[i] ^ 0x36363636;
                exKey[1][i] = key[i] ^ 0x5C5C5C5C;
            }
            this._baseHash[0].update(exKey[0]);
            this._baseHash[1].update(exKey[1]);
            this._resultHash = new Hash(this._baseHash[0]);
        };
        sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (data) {
            if (!this._updated) {
                this.update(data);
                return this.digest(data);
            } else {
                throw new sjcl.exception.invalid("encrypt on already updated hmac called!");
            }
        };
        sjcl.misc.hmac.prototype.reset = function () {
            this._resultHash = new this._hash(this._baseHash[0]);
            this._updated = false;
        };
        sjcl.misc.hmac.prototype.update = function (data) {
            this._updated = true;
            this._resultHash.update(data);
        };
        sjcl.misc.hmac.prototype.digest = function () {
            let w = this._resultHash.finalize(), result = new (this._hash)(this._baseHash[1]).update(w).finalize();
            this.reset();
            return result;
        };
        sjcl.misc.pbkdf2 = function (password, salt, count, length, Prff) {
            count = count || 10000;
            if (length < 0 || count < 0) {
                throw new sjcl.exception.invalid("invalid params to pbkdf2");
            }
            if (typeof password === "string") {
                password = sjcl.codec.utf8String.toBits(password);
            }
            if (typeof salt === "string") {
                salt = sjcl.codec.utf8String.toBits(salt);
            }
            Prff = Prff || sjcl.misc.hmac;
            let prf = new Prff(password),
                u, ui, i, j, k, out = [], b = sjcl.bitArray;
            for (k = 1; 32 * out.length < (length || 1); k++) {
                u = ui = prf.encrypt(b.concat(salt, [k]));
                for (i = 1; i < count; i++) {
                    ui = prf.encrypt(ui);
                    for (j = 0; j < ui.length; j++) {
                        u[j] ^= ui[j];
                    }
                }
                out = out.concat(u);
            }
            if (length) {out = b.clamp(out, length);}
            return out;
        };
        sjcl.random = {
            randomWords: function (nbytes) {
                function getCryptoModule() {
                    try {
                        return require("crypto");
                    }
                    catch (e) {
                        return null;
                    }
                }
                let crypto;
                if (typeof window !== "undefined") {
                    if (window.crypto) {
                        crypto = window.crypto;
                    } else if (window.msCrypto) {
                        crypto = window.msCrypto;
                    }
                } else if (typeof self !== "undefined" && self.crypto) {
                    crypto = self.crypto;
                } else if (typeof module !== "undefined" && module.exports) {
                    crypto = getCryptoModule();
                } else if (typeof global !== "undefined" && global.crypto) {
                    crypto = global.crypto;
                }
                try {
                    if (crypto) {
                        if (crypto.getRandomValues) {
                            return sjcl.codec.bytes.toBits(crypto.getRandomValues(new Uint8Array(nbytes)));
                        }
                        if (crypto.randomBytes) {
                            return sjcl.codec.bytes.toBits(new Uint8Array(crypto.randomBytes(nbytes)));
                        }
                    } else {
                        return getRandomValues(nbytes);
                    }
                } catch (e) {
                    return getRandomValues(nbytes);
                }
            },
            getRandomValues: function (nbytes) {
                let words = [];
                let r = function (m_w) {
                    let m_z = 0x3ade68b1;
                    let mask = 0xffffffff;
                    return function () {
                        m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
                        m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
                        let result = ((m_z << 0x10) + m_w) & mask;
                        result /= 0x100000000;
                        result += 0.5;
                        return result * (Math.random() > .5 ? 1 : -1);
                    };
                };
                for (let i = 0, rcache; i < nbytes; i += 4) {
                    let _r = r((rcache || Math.random()) * 0x100000000);
                    rcache = _r() * 0x3ade67b7;
                    words.push((_r() * 0x100000000) | 0);
                }
                return words;
            }
        };
        sjcl.mode.ctr = {
            name: "ctr",
            encrypt: function (prf, plaintext, iv) {
                return sjcl.mode.ctr._calculate(prf, plaintext, iv);
            },
            decrypt: function (prf, ciphertext, iv) {
                return sjcl.mode.ctr._calculate(prf, ciphertext, iv);
            },
            _calculate: function (prf, data, iv) {
                let l, bl, res, c, d, e, i;
                if (sjcl.bitArray.bitLength(iv) !== 128) {
                    throw new sjcl.exception.invalid("ctr iv must be 128 bits");
                }
                if (!(l = data.length)) {
                    return [];
                }
                c = iv.slice(0);
                d = data.slice(0);
                bl = sjcl.bitArray.bitLength(d);
                for (i = 0; i < l; i += 4) {
                    e = prf.encrypt(c);
                    d[i] ^= e[0];
                    d[i + 1] ^= e[1];
                    d[i + 2] ^= e[2];
                    d[i + 3] ^= e[3];
                    for (let carry = 3; carry >= 0; carry--) {
                        if (++c[carry]) break;
                    }
                }
                return sjcl.bitArray.clamp(d, bl);
            }
        };
    <\/script>
    <script>
        const encryptedHTML = "` + baseRes + `";
        passData.focus();
        passData.oninput = () => {
            if (passData.value.trim().length) {
                goChat.classList.add("activeBtn");
            } else {
                goChat.classList.remove("activeBtn");
            }
        }
        goChat.onclick = () => {
            decryptString(encryptedHTML, passData.value);
        }
        const decoder = new TextDecoder();
        const passwordVerifierLen = 4;
        const aesKeyLen = 16; // aes-128-ctr
        const saltLen = 8;
        const base64ToUint8Array = (base64) => {
            let byteString = atob(base64);
            let bytes = new Uint8Array(byteString.length);
            for (let i = 0; i < byteString.length; i++) {
                bytes[i] = byteString.charCodeAt(i);
            }
            return bytes
        }
        const decryptFromKey = (derivedKey, uint8Data) => {
            const derivedPassVerifier = sjcl.bitArray.bitSlice(derivedKey, aesKeyLen * 8);
            const passVerifyValue = sjcl.codec.bytes.toBits(uint8Data.subarray(saltLen, saltLen + passwordVerifierLen));
            if (!sjcl.bitArray.equal(passVerifyValue, derivedPassVerifier)) {
                alert("密码错误，请重试！")
                return;
            }
            ` + (enableRemember.checked ? `if (rememberMe && rememberMe.checked) {
                let baseKey = btoa(String.fromCharCode.apply(null, sjcl.codec.bytes.fromBits(derivedKey)));
                localStorage.setItem("staticDerivedKey", baseKey);
                if (expireDays) {
                    localStorage.setItem("staticKeyExpire", new Date().getTime() + expireDays * 8.64e7);
                }
            }` : "") +
                    `const aesKey = sjcl.bitArray.bitSlice(derivedKey, 0, aesKeyLen * 8);
            const encryptedData = uint8Data.subarray(saltLen + passwordVerifierLen);
            let result = new Uint8Array(sjcl.codec.bytes.fromBits(sjcl.mode.ctr.decrypt(new sjcl.cipher.aes(aesKey), sjcl.codec.bytes.toBits(encryptedData), [0, 0, 0, 0])));
            if (self.inflateSync) {
                result = self.inflateSync(result);
            }
            const utf8Result = decoder.decode(result)
            document.write(utf8Result);
            document.close();
        }
        const decryptString = (data, password) => {
            const uint8Data = base64ToUint8Array(data);
            const salt = sjcl.codec.bytes.toBits(uint8Data.subarray(0, saltLen));
            const derivedKey = sjcl.misc.pbkdf2(password, salt, 1000, (aesKeyLen + passwordVerifierLen) * 8);
            decryptFromKey(derivedKey, uint8Data)
        }
        ` + (enableRemember.checked ? `const expireDays = ${expireDays.value || 0};
        window.onload = () => {
            let localKey = localStorage.getItem("staticDerivedKey");
            if (localKey) {
                let localExpire = localStorage.getItem("staticKeyExpire")
                if (localExpire && (localExpire < new Date().getTime())) {
                    localStorage.removeItem("staticDerivedKey")
                    return;
                }
                const derivedKey = sjcl.codec.bytes.toBits(base64ToUint8Array(localKey));
                const uint8Data = base64ToUint8Array(encryptedHTML);
                decryptFromKey(derivedKey, uint8Data);
            }
        }`: "") + `
    <\/script>
</body>

</html>`;
                outputData.value = htmlRes;
                downHTML.style.display = outputData.style.display = "block";
            }
            reader.readAsDataURL(new Blob([new Uint8Array(sjcl.codec.bytes.fromBits(sjcl.bitArray.concat(preData, result)))]))
        }
        function decryptString(data, password) {
            const byteString = window.atob(data);
            const uint8Data = new Uint8Array(byteString.length);
            for (let i = 0; i < byteString.length; i++) {
                uint8Data[i] = byteString.charCodeAt(i);
            }
            const salt = sjcl.codec.bytes.toBits(uint8Data.subarray(0, saltLen));
            const derivedKey = sjcl.misc.pbkdf2(password, salt, 1000, (aesKeyLen + passwordVerifierLen) * 8);
            const derivedPassVerifier = sjcl.bitArray.bitSlice(derivedKey, aesKeyLen * 8);
            const passVerifyValue = sjcl.codec.bytes.toBits(uint8Data.subarray(saltLen, saltLen + passwordVerifierLen));
            if (!sjcl.bitArray.equal(passVerifyValue, derivedPassVerifier)) {
                throw new Error("Wrong password!");
            }
            const aesKey = sjcl.bitArray.bitSlice(derivedKey, 0, aesKeyLen * 8);
            const encryptedData = uint8Data.subarray(saltLen + passwordVerifierLen);
            const result = sjcl.mode.ctr.decrypt(new sjcl.cipher.aes(aesKey), sjcl.codec.bytes.toBits(encryptedData), [0, 0, 0, 0]);
            const utf8Result = decoder.decode(new Uint8Array(sjcl.codec.bytes.fromBits(result)))
            console.log(utf8Result);
        }
    </script>
</body>

</html>